﻿/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.util.profiler;

class CodeBlockExecutionStats {
	
	public var executionDuration(default, null):NumericalStat;
	public var overallDuration(getDuration, null):Float;
	
	public function new() {
		executionDuration = new NumericalStat();
	}
	
	public function addCall(time:Float) {
		executionDuration.update(time * 1000);
	}
	
	public function containsData() {
		return executionDuration.sum > 0.0;
	}
	
	public function toString() {
		var r = function(x:Float) { return Math.round(x * 100) / 100; };
		var e = executionDuration;
		return e.count + " calls | AVG: " + 
			r(e.avg) + " ms. | OVERALL: " +r(e.sum) +
			" ms. | MAX: " + r(e.max) + " ms. | MIN: " + 
			r(e.min) + " ms.";
	}
	
	function getDuration() {
		return executionDuration.sum;
	}
}